#include "time_utils.hpp"

using namespace vpm::utils;

#if defined( WIN32 )
#  include <windows.h>
#  include <winbase.h>
#else
#  include <sys/time.h>
#  include <unistd.h>
#endif

#include <cassert>


UInt64 TimeUtils::getTimeMicroSec()
{
	return getSystemTime();
}
UInt64 TimeUtils::getTimeMs()
{
	return getSystemTime()/1000LL;
}

UInt64 TimeUtils::getTimeSecs()
{
	return getSystemTime()/1000000LL;
}

UInt64 TimeUtils::getSystemTime()
{
	assert( sizeof(UInt64) == 64/8 );
	UInt64 time=0;
#if defined(WIN32)  
	FILETIME ft;
	GetSystemTimeAsFileTime( &ft);
	ULARGE_INTEGER li;
	li.LowPart = ft.dwLowDateTime;
	li.HighPart = ft.dwHighDateTime;
	time = li.QuadPart/10;
#else
	struct timeval now;
	gettimeofday( &now , NULL );
	//assert( now );
	time = now.tv_sec;
	time = time*1000000;
	time += now.tv_usec;
#endif
	return time;
}
  
